import { storeBindingsBehavior } from 'mobx-miniprogram-bindings'
import { getMemberMineInfo } from '@src/api/member';
import member from '@src/store/member'
import base from '@src/store/base'
import router from "@src/router";
import dayjs from "dayjs";
Component({
  behaviors: [storeBindingsBehavior],
  storeBindings: [{
    store: member,
    fields: ['isMember', 'memberName', 'categoryName', 'categoryImage', 'wxName', 'expireTime', 'wxHeadImg', 'cardOrder', 'categoryId'],
    actions: ['getBaseInfo', 'syncWxCard'],
  }, {
    store: base,
    fields: ['themeColor', 'myPageBanners', 'myPageBg', 'perms']
  }],
  properties: {
    login: {
      type: Boolean,
      value: false
    },
    modul: {
      type: Object,
      value: {}
    }
  },
  lifetimes: {
    ready() {
      let fileBaseUrl = getApp().globalData.extConfig.fileBaseUrl
      this.setData({ fileBaseUrl })
      let modul = this.data.modul
      typeof modul.biz.params === 'string' && (modul.biz.params = JSON.parse(modul.biz.params))
      modul.biz.params?.isShow && this.setData({isShow: modul.biz.params.isShow})
      this.fetchData()
    }
  },
  pageLifetimes: {
    show: function () {
      if (!this.data.login) return
      this.fetchData();
    },
  },
  data: {
    fileBaseUrl: '',
    accountInfo: {},
    isShow: null,
    isBind:true
  },

  methods: {
    navigateTo(e) {
      const { url } = e.currentTarget.dataset
      router.push({ path: url })
    },
    handleLogin() {
      this.triggerEvent('handleLogin')
    },
    fetchData() {
      if (!this.data.login) return
      getMemberMineInfo().then(res => {
        console.log('卡数量--', res)
        this.setData({ "accountInfo": res.data, "serviceTime": dayjs(res._header_.Date).format("YYYY-MM-DD HH:mm:ss"),
        'isBind':res.data?.showBindBtn.includes('MEMBER_BIND_DEVICE')?true:false })
      })
    },
    bindSncode(){
      this.selectComponent('#bindSncode').open()
    }
  }
})
